package com.fan.shop.businesslogic;


import org.apache.log4j.Logger;

import com.fan.shop.domain.Category;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.CategoryService;

public class CategoryEditProcess extends ProcExec<Integer> {

	
	private static Logger logger = Logger.getLogger(CategoryEditProcess.class);
	
	
	private String name;
	private String description;
	private String parent;

	private CategoryService categoryService;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	@Override
	public Integer processImpl() {
		Category parentCategory = categoryService.getCategory(parent);

		Category category = categoryService.getCategory(name);
		category.setName(name);
		category.setDescription(description);
		category.setParent(parentCategory.getId());

		categoryService.updateCategory(category);
		return ShopGlobalVariables.SUCCESS;
	}

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		CategoryEditProcess.logger = logger;
	}

}
